Skip to content

Move AI gateway state source of truth from Redis to PostgreSQL - #5970

Merged
chrarnoldus merged 3 commits into
mainfrom
use-ai-gateway-database-state
Sep 9, 2026
Merged

chrarnoldus merged 3 commits into
mainfrom
use-ai-gateway-database-state

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • read gateway routing config, provider-sync timestamps, and request-logging opt-ins from the PostgreSQL singleton tables added in Add database mirrors for AI gateway state #5965
  • enforce request-logging opt-in mutations against a row-locked database record instead of Redis
  • keep Redis compatibility mirrors for migrated state, using a 7-day TTL except for the existing 3-day stale-alert TTL
  • serialize authoritative database mutations with their Redis mirrors so failed or concurrent writes cannot leave stale mirrors
  • preserve three-day stale-sync reminders and normalize database timestamps at the API boundary

Verification

  • formatted changed files with oxfmt
  • git diff --check
  • test, typecheck, and lint suites intentionally left to CI

@chrarnoldus chrarnoldus self-assigned this Sep 8, 2026
Comment thread apps/web/src/lib/ai-gateway/providers/routing-config.ts
Comment thread apps/web/src/lib/ai-gateway/request-logging-opt-ins.ts
@kilo-code-bot

kilo-code-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental restore of the three-day stale-alert Redis TTL matches existing suppression behavior; no issues on the changed lines.

Files Reviewed (2 files)
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers-stale-alert.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers-stale-alert.test.ts
Previous Review Summary (commit cea68b5)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit cea68b5)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

Cutting Redis reads over to empty singleton tables will silently revert live gateway routing to compiled 50/50 defaults unless Redis is backfilled first.

Overview

Severity Count
CRITICAL 1
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
apps/web/src/lib/ai-gateway/providers/routing-config.ts 33 Empty ai_gateway_config row reverts live routing to compiled defaults; Redis override is ignored

WARNING

File Line Issue
apps/web/src/lib/ai-gateway/request-logging-opt-ins.ts 44 Missing opt-in row returns [], dropping Redis opt-ins that were never mutated after #5965
Files Reviewed (8 files)
  • apps/web/src/lib/ai-gateway/providers/routing-config.ts - 1 issue
  • apps/web/src/lib/ai-gateway/request-logging-opt-ins.ts - 1 issue
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers-stale-alert.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers-stale-alert.test.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers.ts
  • apps/web/src/lib/redis-keys.ts
  • apps/web/src/routers/admin-router.ts
  • apps/web/src/routers/admin/gateway-config-router.ts

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 112.4K · Output: 7.6K · Cached: 180.1K

Review guidance: REVIEW.md from base branch main

@chrarnoldus chrarnoldus changed the title Read AI gateway state from database Move AI gateway state source of truth from Redis to PostgreSQL Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants